# FIXME: install assembly and pascal includes into the correct locations

lib_target = "pluginapi"

lib_files = Split("""
	pluginapi.c
""")

api_files = Split("""
	pluginapi.h
	nsis_tchar.h
	#Source/exehead/api.h
""")

example = Split("""
	exdll.c
	exdll.dpr
	exdll.dsp
	exdll.dsw
	exdll_with_unit.dpr
	exdll-vs2008.sln
	exdll-vs2008.vcproj
	nsis.pas
	extdll.inc
""")

Import('env plugin_env plugin_uenv GetArcSuffix PerformPluginExtrasDistOperationOnce')

unicodetarget = 'UNICODE' in env['CPPDEFINES']
plugin_envT = plugin_env
if unicodetarget:
	plugin_envT = plugin_uenv
lib_targetT = lib_target + '-' + GetArcSuffix(plugin_envT, unicodetarget)



# build library

api_envT = plugin_envT.Clone()
api_envT.Append(CPPPATH = ['#Source/exehead']) # For api.h
lib = api_envT.Library(lib_targetT, lib_files)


# distribute library, files and examples

if PerformPluginExtrasDistOperationOnce(plugin_envT, unicodetarget):
	env.DistributeExamples(api_files, path='Plugin/nsis')
	env.DistributeExamples(example, path='Plugin')
	if env['PLATFORM'] != 'win32':
		if 'PREFIX_PLUGINAPI_INC' in env:
			env.Distribute(api_files, None, 'pluginapi_inc', '', 'nsis', 'pluginapi', 'pluginapi')


if env['PLATFORM'] == 'win32':
	env.DistributeExamples(lib, path='Plugin/nsis')
else:
	example += lib_files

	if 'PREFIX_PLUGINAPI_LIB' in env:
		env.Distribute(lib, None, 'pluginapi_lib', '', 'nsis', 'pluginapi', 'pluginapi')


# make sure all the other plug-ins can use the library

if PerformPluginExtrasDistOperationOnce(plugin_envT, unicodetarget):
	env.Install('#$BUILD_PREFIX/api/nsis', api_files)

env.Install('#$BUILD_PREFIX/api/nsis', lib)
plugin_envT.Append(CPPPATH = ['#$BUILD_PREFIX/api'])
plugin_envT.Append(LIBPATH = ['#$BUILD_PREFIX/api/nsis'])
plugin_envT.Append(LIBS = [lib_targetT])

